﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using Cinemon;
using Cinemon.MySqlConnect;
public partial class Movie_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == true)
        {
            using (DatabaseManager manager = new DatabaseManager())
            {
                List<MySqlParameter> param = new List<MySqlParameter> {
				new MySqlParameter("mid", Int32.Parse(movieID.Text)),
				new MySqlParameter("movieName", movieName.Text),
				new MySqlParameter("mtime", showtime.Text),
				new MySqlParameter("licenid", LicenseDrop.SelectedValue.ToString()),
                new MySqlParameter("poster", imageURL.Text)
			};
                manager.ExecuteNonQuery("updateMovie", param);
            }
            Response.Redirect("view.aspx");
            
        }
        int id = Int32.Parse(Request.QueryString["id"]);
        movieID.Text = id.ToString();

        using (DatabaseManager manager = new DatabaseManager())
        {
            LicenseDrop.DataSource = manager.ExecuteQuery("GetAllLicenses");
            LicenseDrop.DataTextField = "Company";
            LicenseDrop.DataValueField = "License ID";
            LicenseDrop.DataBind();            
        }
        LicenseDrop.SelectedValue = id.ToString();
        
        using (DatabaseManager manager = new DatabaseManager())
        {
            List<MySqlParameter> param = new List<MySqlParameter> {
				new MySqlParameter("numberm",id)
			};
            DataTable table = manager.ExecuteQuery("GetMovie", param);
            movieName.Text = table.Rows[0]["movie_name"].ToString();
            imageURL.Text = table.Rows[0]["movie_poster_image"].ToString();
            showtime.Text = table.Rows[0]["movie_showTime"].ToString();
           
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("view.aspx");
    }
}